package com.lepu.app.fun.my.adapter;

import java.util.ArrayList;
import java.util.Date;

import android.annotation.SuppressLint;
import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.core.lib.utils.DensityUtil;
import com.core.lib.utils.main.DateUtilBase;
import com.core.lib.utils.main.ImageUtilBase;
import com.core.lib.utils.photo.UniversalImageLoadTool;
import com.eyzhs.app.R;
import com.lepu.app.fun.grow.bean.HotPhoto;

public class AdapterPubContentHotPhoto extends BaseAdapter {

	private LayoutInflater mLayoutInflater = null;
	private Context mContext = null;
	private ArrayList<HotPhoto> mArrayList = null;

	public AdapterPubContentHotPhoto(Context context,
			ArrayList<HotPhoto> arrayList) {
		mContext = context;
		mLayoutInflater = LayoutInflater.from(context);
		mArrayList = arrayList;
	}

	@Override
	public int getCount() {
		int size = 0;
		if (mArrayList != null && mArrayList.size() > 0) {
			size = mArrayList.size();
		}
		return size;
	}

	@Override
	public Object getItem(int position) {
		return position;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@SuppressLint("InflateParams")
	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {

		final ViewHolder holder;

		if (convertView == null) {
			convertView = mLayoutInflater.inflate(
					R.layout.my_pub_phone_content_listitem, null);

			holder = new ViewHolder();

			ImageView iconImageView = (ImageView) convertView
					.findViewById(R.id.iconImageView);
			TextView titleTextView = (TextView) convertView
					.findViewById(R.id.titleTextView);
			TextView subTitleTextView = (TextView) convertView
					.findViewById(R.id.subTitleTextView);
			TextView pubTimeTextView = (TextView) convertView
					.findViewById(R.id.pubTimeTextView);
			TextView statusTextView = (TextView) convertView
					.findViewById(R.id.statusTextView);
			TextView deleteTextView = (TextView) convertView
					.findViewById(R.id.deleteTextView);

			holder.iconImageView = iconImageView;
			holder.titleTextView = titleTextView;
			holder.subTitleTextView = subTitleTextView;
			holder.pubTimeTextView = pubTimeTextView;
			holder.statusTextView = statusTextView;
			holder.deleteTextView = deleteTextView;

			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		final HotPhoto item = mArrayList.get(position);

		int widthHeight = DensityUtil.dip2px(mContext, 90);
		RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(widthHeight*16/9,widthHeight);
		holder.iconImageView.setLayoutParams(layoutParams);
		
		if(!TextUtils.isEmpty(item.AlbumCover))
		{
			UniversalImageLoadTool.disPlay(item.AlbumCover,
					holder.iconImageView, R.drawable.album_cover_default);
		}else{
			UniversalImageLoadTool.disPlay(ImageUtilBase
					.getDrawableImageUrl(R.drawable.album_cover_default),
					holder.iconImageView, R.drawable.album_cover_default);
		}

		holder.titleTextView.setText(item.AlbumDescription);
		holder.subTitleTextView.setText("");
		
		Date date = DateUtilBase.dateFromString(item.CreateTime, DateUtilBase.DATE_ALL);
		holder.pubTimeTextView.setText(DateUtilBase.stringFromDate(date, "yyyy年MM月dd HH:mm"));

		if(TextUtils.isEmpty(item.CheckStatus))
		{
			holder.statusTextView.setText("");
		}else{
			if (item.CheckStatus.equals("2")) {
				holder.statusTextView.setText("未通过");
			} else {
				holder.statusTextView.setText("");
			}
		}
		
		holder.deleteTextView.setVisibility(View.GONE);

		return convertView;
	}

	private static class ViewHolder {

		ImageView iconImageView;
		TextView titleTextView;
		TextView subTitleTextView;
		TextView pubTimeTextView;
		TextView statusTextView;
		TextView deleteTextView;

	}
}
